﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMLGener.Interfaces;
using XMLGener.Data;
using RegexDataGenerator;
using RegularExpressionDataGenerator;

namespace XBasicModules
{
    class PatternGenerator:ModuleBase,XMLGenerModuleInterface
    {
        #region XMLGenerModuleInterface Members

        private string pattern = "";

        RegExpDataGenerator regexpGenerator = null;
        /// <summary>
        /// Return user defined string.
        /// </summary>
        /// <returns></returns>
        public string generate()
        {
            if (regexpGenerator != null)
                return regexpGenerator.Next();
            return "";
        }

        /// <summary>
        /// return this module definition
        /// </summary>
        /// <returns>definition</returns>
        public string getDefinition()
        {
            return
              "<function>" +
              "    <name>Pattern generator</name>" +
              "    <id>patternGenerator</id>" +
              "    <type>string</type>" +
              "    <attributes>" +
              "       <attribute>" +
              "          <name>Pattern</name>" +
              "          <id>text</id>" +
              "          <type>text</type>" +
              "       </attribute>" +
              "    </attributes>" +
              "   <acceptrestriction>pattern</acceptrestriction>" +
              "</function>";

        }

        /// <summary>
        /// set attributes to this module
        /// </summary>
        /// <param name="xmlParams"></param>
        /// <param name="parentDocument"></param>
        public void setParameters(string xmlParams, XMLGenerDocument parentDocument)
        {
            if (!this.checkSettingsElement(xmlParams, parentDocument))
                return;
            this.pattern = this.getParam("text");
            if (this.restrictions!=null && this.restrictions.usePattern)
                pattern = restrictions.pattern;
            regexpGenerator = new RegExpDataGenerator(pattern);

        }

        #endregion
    }
}
